<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>登录</title>
		<script src="js/mui.min.js"></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/register.css"/>
		<link rel="stylesheet" type="text/css" href="css/public.css"/>
		<link rel="stylesheet" type="text/css" href="css/app.css"/>
		<script type="text/javascript" charset="utf-8">
			mui.init();
			
		</script>
	</head>

	<body>
	<!--------头部返回----------->
		<div id="headerNav"></div>
	<!--------填写登录内容----------->
		<div class="mui-content" style="background:white;margin-top:45px;">
			<div class="mui-input-group">
				<div class="mui-input-row" style="height:60px;line-height: 60px;">
					<!--<label>用户名：</label>-->
					<input type="text" class="mui-input-clear" id="username" placeholder="请输入用户名">
				</div>
				<div class="mui-input-row" style="height:60px;line-height:60px;">
					<!--<label>密码：</label>-->
					<input type="password" class="mui-input-clear" id="passwordTest" placeholder="请输入密码">
				</div>
			</div>
	<!--------确认登录----------->
			<div class="mui-button-row" style="background:white;margin-top:22px;">
				<button type="button" class="mui-btn mui-btn-primary" id="btn" style="width:95%;height:50px;background:#5763FF;font-size: 16px;">登录</button>
			</div>
			<div class="mui-card-content-inner">
				<a href="login.html" id="register">立即注册</a><a href="forgetPassword.html" id="forget">忘记密码<a>
			</div>
		</div>
	</body>
	<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
	<script type="text/javascript">
		$('#headerNav').load('header.html',function(){
			$('header h1').html('登陆');
		});
		mui('body').on('tap','a',function(){
	        window.top.location.href = this.href;
	    })
	</script>
	<script type="text/javascript">
		$("#btn").click(function(){
			var username = $("#username").val();
			var passwordTest = $("#passwordTest").val();
			if(username==''||passwordTest==''){
				mui.alert('','用户名或密码不能为空');
				return true;
			}else{
				$.ajax({
					type: "post",
					url: "http://mall.itcn99.com/i/index/user_login",
					dataType: "jsonp",
					async: true,
					data: {
						"mobile":username,
						"user_password":passwordTest,
					},
					success: function(data) {
						console.log(data);
						var state = data.state;
						console.log(state);
						if(!window.localStorage) {
								alert("浏览器支持localstorage");

							} else {
								var storage = window.localStorage;
								//写入a字段
								localStorage.setItem("state", state);
								var a = localStorage.state;
								var data = data.data
								localStorage.setItem("data", data);
								var b = localStorage.data;
								console.log(b);
							}
							if(a == 1) {
								mui.alert('','登录成功',function(){
									location.href="index.html";
								})
								
							}else{
								mui.alert('','账号或密码错误，请重新输入')
							}
//						state的值：0是账号不存在，1是登陆成功，2密码错误，3是账号禁用
						if(data.state==0){
							mui.alert('','账号不存在');
						}else if(data.state==2){
							mui.alert('','密码错误');
						}else if(data.state==3){
							mui.alert('','您的帐号已禁用');
						}else if(data.state==1){
//							window.location.href="index.html";
						}
					}
				})
			}
			
		})
	</script>
</html>